<?php
/**
 * class Connection
 *
 * Description for class Connection
 *
 * @author: hqlam
*/
abstract class Connection  {

	private static $connection = null;	// php connection indentifier
	
	/**
	 * GetConnection
	 *
	 * @return php connection 
	 * Singleton Pattern
	 */
	public static function GetConnection() {
		$HOST = 'localhost';
		$USERNAME = 'root';
		$PASSWORD = '';
		$DATABASE = 'nhanviendb';
		
		if (Connection::$connection == null) {
			$con = mysql_connect($HOST, $USERNAME, $PASSWORD);
			if (!$con) {
				throw new Exception('Could not connect to database.');
			}
			
			if (!mysql_select_db($DATABASE, $con)) {
				throw new Exception('Database not exist.');
			}
	
			mysql_query("set names 'utf8'", $con);
			Connection::$connection = $con;
		}
		return Connection::$connection;
	}

}

?>